﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GA.Server.Api;
using GA.Server.Configuration;
using GA.Server.Objects;
using GA.Server.ConnectionListener;
using GA.Shared.Objects;
using GA.Shared.Interfaces;

namespace GA.Server.Managers
{
    public class PlayerManagerServer : GAServer, IObjectServer
    {
        public override string Name
        {
            get { return "PlayerManagerServer"; }
        }

        public PlayerManagerServer()
        {
        }

        public PlayerManagerServer(ServerPropertiesElementCollection properties)
            : base(properties)
        {
            Log.Info("Starting PlayerManagerServer...");

            mPlayers = new Dictionary<int, DatabasePlayer>();
            mCharacters = new Dictionary<int, DatabaseCharacter>();
            mSkills = new Dictionary<int, DatabaseSkill>();
            mSkillTypes = new Dictionary<int, DatabaseSkillType>();
        }

        public override void RegisterServer(GAServer newServer)
        {
            if (newServer is ConnectionListenerServer)
            {
                ((ConnectionListenerServer)newServer).RegisterObjectServer<Player>(this);
                ((ConnectionListenerServer)newServer).RegisterObjectServer<Character>(this);
                ((ConnectionListenerServer)newServer).RegisterObjectServer<Skill>(this);
                ((ConnectionListenerServer)newServer).RegisterObjectServer<SkillType>(this);
            }
            else if (newServer is UserManagerServer)
            {
                mUserManagerServer = (UserManagerServer)newServer;
            }
        }

        private Dictionary<int, DatabasePlayer> mPlayers;
        private Dictionary<int, DatabaseCharacter> mCharacters;
        private Dictionary<int, DatabaseSkill> mSkills;
        private Dictionary<int, DatabaseSkillType> mSkillTypes;
        private UserManagerServer mUserManagerServer;


        #region IObjectServer Members

        public SerializableTransferObject CreateObject(SerializableTransferObject authorizedUser, SerializableTransferObject newObject)
        {
            DatabaseUser realUser = mUserManagerServer.GetRealUser(authorizedUser.ConvertToLinkedDependencyObject<User>());

            switch (newObject.OutputType)
            {
                case "Player":
                    break;
                case "Character":
                    break;
                case "Skill":
                    break;
                case "SkillType":
                    break;
            }
            return null;
        }

        public void EditObject(SerializableTransferObject authorizedUser, SerializableTransferObject editObject)
        {
            #warning Not Implemented
        }

        public void DeleteObject(SerializableTransferObject authorizedUser, SerializableTransferObject deleteObject)
        {
            #warning Not Implemented
        }

        public SerializableTransferObject GetObject(SerializableTransferObject authorizedUser, string type, Dictionary<string, object> parameters)
        {
            #warning Not Implemented
            throw new NotImplementedException();
        }

        public IEnumerable<SerializableTransferObject> GetObjects(SerializableTransferObject authorizedUser, string type, Dictionary<string, object> parameters)
        {
            #warning Not Implemented
            throw new NotImplementedException();
        }

        #endregion

        #region Player Handlers

        private void Player_New(User authorizedUser, Player incomingPlayer)
        {
            
        }

        #endregion
    }
}
